<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态文字弹幕</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            overflow: hidden;
        }

        .danmaku-container {
            position: relative;
            width: 100vw;
            height: 100vh;
            overflow: hidden;
            background: rgba(0, 0, 0, 0.1);
        }

        .danmaku {
            position: absolute;
            white-space: nowrap;
            font-size: 20px;
            font-weight: bold;
            color: #fff;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
            cursor: pointer;
            transition: transform 0.1s ease;
            z-index: 10;
        }

        .danmaku:hover {
            transform: scale(1.1);
            text-shadow: 3px 3px 6px rgba(0, 0, 0, 1);
        }

        .control-panel {
            position: fixed;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(255, 255, 255, 0.95);
            padding: 20px;
            border-radius: 15px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            backdrop-filter: blur(10px);
            z-index: 1000;
            display: flex;
            gap: 15px;
            align-items: center;
        }

        .input-group {
            display: flex;
            gap: 10px;
            align-items: center;
        }

        #danmakuInput {
            padding: 12px 16px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            width: 250px;
            outline: none;
            transition: border-color 0.3s ease;
        }

        #danmakuInput:focus {
            border-color: #667eea;
        }

        .btn {
            padding: 12px 20px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            outline: none;
        }

        .btn-primary {
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
        }

        .btn-secondary {
            background: #f8f9fa;
            color: #333;
            border: 2px solid #ddd;
        }

        .btn-secondary:hover {
            background: #e9ecef;
            border-color: #adb5bd;
        }

        .speed-control {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        #speedSlider {
            width: 100px;
        }

        .stats {
            position: fixed;
            top: 20px;
            right: 20px;
            background: rgba(255, 255, 255, 0.9);
            padding: 15px;
            border-radius: 10px;
            font-size: 14px;
            color: #333;
        }

        @keyframes danmakuFloat {
            0% {
                transform: translateX(100vw);
            }
            100% {
                transform: translateX(-100%);
            }
        }

        .rainbow {
            background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #96ceb4, #feca57, #ff9ff3);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
    </style>
</head>
<body>
    <div class="danmaku-container" id="danmakuContainer"></div>
    
    <div class="control-panel">
        <div class="input-group">
            <input type="text" id="danmakuInput" placeholder="输入弹幕内容..." maxlength="50">
            <button class="btn btn-primary" onclick="sendDanmaku()">发送弹幕</button>
        </div>
        <div class="speed-control">
            <label>速度:</label>
            <input type="range" id="speedSlider" min="3" max="15" value="8">
            <span id="speedValue">8</span>
        </div>
        <button class="btn btn-secondary" onclick="clearDanmaku()">清空弹幕</button>
    </div>

    <div class="stats">
        <div>当前弹幕数: <span id="danmakuCount">0</span></div>
        <div>总发送数: <span id="totalSent">0</span></div>
    </div>

    <script>
        let danmakuSpeed = 8;
        let danmakuCount = 0;
        let totalSent = 0;
        let activeDanmaku = new Set();

        // 预设弹幕内容
        const presetDanmaku = [
            '666666', '太棒了！', '哈哈哈', '前排围观', '太厉害了',
            '支持一下', '来了来了', '精彩精彩', '加油加油', '太赞了',
            '必须点赞', '超级棒', '太有趣了', '笑死我了', '太酷了'
        ];

        // 随机颜色数组
        const colors = [
            '#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4', '#feca57',
            '#ff9ff3', '#54a0ff', '#5f27cd', '#00d2d3', '#ff9f43'
        ];

        // 速度滑块事件
        document.getElementById('speedSlider').addEventListener('input', function() {
            danmakuSpeed = this.value;
            document.getElementById('speedValue').textContent = this.value;
        });

        // 发送弹幕
        function sendDanmaku() {
            const input = document.getElementById('danmakuInput');
            const text = input.value.trim();
            
            if (text === '') {
                // 随机发送预设弹幕
                const randomText = presetDanmaku[Math.floor(Math.random() * presetDanmaku.length)];
                createDanmaku(randomText);
            } else {
                createDanmaku(text);
                input.value = '';
            }
        }

        // 创建弹幕元素
        function createDanmaku(text) {
            const container = document.getElementById('danmakuContainer');
            const danmaku = document.createElement('div');
            danmaku.className = 'danmaku';
            danmaku.textContent = text;
            
            // 随机颜色和样式
            const color = colors[Math.floor(Math.random() * colors.length)];
            const fontSize = 16 + Math.random() * 12;
            const topPosition = Math.random() * (window.innerHeight - 100);
            const duration = (20 - danmakuSpeed) + Math.random() * 5;
            
            // 特殊效果
            if (Math.random() < 0.1) {
                danmaku.classList.add('rainbow');
            } else {
                danmaku.style.color = color;
            }
            
            danmaku.style.fontSize = fontSize + 'px';
            danmaku.style.top = topPosition + 'px';
            danmaku.style.animation = `danmakuFloat ${duration}s linear`;
            
            // 点击事件
            danmaku.addEventListener('click', function() {
                this.style.animationPlayState = 'paused';
                setTimeout(() => {
                    this.style.animationPlayState = 'running';
                }, 2000);
            });
            
            // 动画结束事件
            danmaku.addEventListener('animationend', function() {
                if (activeDanmaku.has(this)) {
                    activeDanmaku.delete(this);
                    updateStats();
                }
                this.remove();
            });
            
            container.appendChild(danmaku);
            activeDanmaku.add(danmaku);
            
            totalSent++;
            updateStats();
        }

        // 清空弹幕
        function clearDanmaku() {
            const container = document.getElementById('danmakuContainer');
            container.innerHTML = '';
            activeDanmaku.clear();
            updateStats();
        }

        // 更新统计信息
        function updateStats() {
            document.getElementById('danmakuCount').textContent = activeDanmaku.size;
            document.getElementById('totalSent').textContent = totalSent;
        }

        // 回车发送
        document.getElementById('danmakuInput').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                sendDanmaku();
            }
        });

        // 自动生成弹幕
        function autoGenerateDanmaku() {
            if (Math.random() < 0.3) {
                const randomText = presetDanmaku[Math.floor(Math.random() * presetDanmaku.length)];
                createDanmaku(randomText);
            }
        }

        // 启动自动弹幕生成
        setInterval(autoGenerateDanmaku, 2000);

        // 初始化一些弹幕
        for (let i = 0; i < 5; i++) {
            setTimeout(() => {
                const randomText = presetDanmaku[Math.floor(Math.random() * presetDanmaku.length)];
                createDanmaku(randomText);
            }, i * 500);
        }

        // 页面加载完成提示
        window.addEventListener('load', function() {
            setTimeout(() => {
                createDanmaku('欢迎来到弹幕世界！');
            }, 1000);
        });
    </script>
</body>
</html>